﻿/**************************************************************************
创建时间:	2020/8/28 8:40:59    
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com

Copyright (c) zhcun.cn

描	述：
记	录：
***************************************************************************/
using ASmile.Extend;
using System;

namespace ASmile.Win
{
    /// <summary>
    /// 登陆用户状态，只能设置一次
    /// </summary>
    public class LoginUser
    {
        static string _UserName;
        static string _RoleName;
        static string _DeptName;
        static bool? _IsManager;
        static string _UserId;
        static string _DeptId;
        static string _RoleId;

        public static event Action OnResetUser;

        public static void ResetLoginUser()
        {
            LogHelper.LogObj.Info("重置了 LoginUser");
            OnResetUser?.Invoke();
            _UserName = null;
            _RoleName = null;
            _DeptName = null;
            _IsManager = null;
            _UserId = null;
            _DeptId = null;
            _RoleId = null;
        }
        /// <summary>
        /// 重置科室Id及名称，切换部门使用
        /// </summary>
        public static void ResetDept(string deptId, string deptName)
        {
            OnResetUser?.Invoke();
            _DeptId = deptId;
            _DeptName = deptName;
        }
        /// <summary>
        /// 当前登陆用户Id
        /// </summary>
        public static string UserId
        {
            set
            {
                if (!_UserId.IsEmpty())
                {
                    throw new Exception("已经设置 UserId，不允许操作");
                }
                _UserId = value;
            }
            get { return _UserId; }
        }        
        /// <summary>
        /// 当前用户的用户名
        /// </summary>
        public static string UserName
        {
            set
            {
                if (!_UserName.IsEmpty())
                {
                    throw new Exception("已经设置 UserName，不允许操作");
                }
                _UserName = value;
            }
            get { return _UserName; }
        }
        /// <summary>
        /// 当前角色Id
        /// </summary>
        public static string RoleId
        {
            set
            {
                if (!_RoleId.IsEmpty())
                {
                    throw new Exception("已经设置 RoleId，不允许操作");
                }
                _RoleId = value;
            }
            get { return _RoleId; }
        }
        /// <summary>
        /// 当前用户角色名称
        /// </summary>
        public static string RoleName
        {
            set
            {
                if (!_RoleName.IsEmpty())
                {
                    throw new Exception("已经设置 RoleName，不允许操作");
                }
                _RoleName = value;
            }
            get { return _RoleName; }
        }
        /// <summary>
        /// 当前科室Id
        /// </summary>
        public static string DeptId
        {
            set
            {
                if (!_DeptId.IsEmpty())
                {
                    throw new Exception("已经设置 DeptId，不允许操作");
                }
                _DeptId = value;
            }
            get { return _DeptId; }
        }
        /// <summary>
        /// 当前用户科室名称
        /// </summary>
        public static string DeptName
        {
            set
            {
                if (!_DeptName.IsEmpty())
                {
                    throw new Exception("已经设置 DeptName，不允许操作");
                }
                _DeptName = value;
            }
            get { return _DeptName; }
        }
        /// <summary>
        /// 是否管理员
        /// </summary>
        public static bool? IsManager
        {
            set
            {
                if (_IsManager != null)
                {
                    throw new Exception("已经设置 IsManager，不允许操作");
                }
                _IsManager = value;
            }
            get { return _IsManager; }
        }
    }
}